<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title></title>
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
		<script language="javascript">

function LoadUsingCreateElement()
{
	// Create the script element.
	var e = document.createElement( "script" ) ;
	e.type	= "text/javascript" ;

	// Add the new object to the HEAD.
	document.getElementsByTagName("head")[0].appendChild( e ) ;

	// Load the script.
	// Gecko fires the "onload" event and IE fires "onreadystatechange"
	e.onload = e.onreadystatechange = LoadUsingCreateElement_OnLoad ;
	e.src = 'test.js' ;
}

function LoadUsingCreateElement_OnLoad()
{
	if ( !this.readyState || this.readyState == 'loaded' )
		ShowMessage() ;
}

function LoadUsingXMLHttpRequest()
{
	var oXmlRequest ;

	// IE uses the ActiveX way, gecko the XMLHttpRequest native object.
	if ( window.ActiveXObject )
		oXmlRequest = new ActiveXObject("Microsoft.XMLHTTP") ;
	else
		oXmlRequest = new XMLHttpRequest() ;

	// Load the script synchronously.
	oXmlRequest.open( "GET", 'test.js', false ) ;
	oXmlRequest.send( null ) ;

	// Evaluate the script.
	if ( oXmlRequest.status == 200 )
		eval( oXmlRequest.responseText ) ;

	ShowMessage() ;
}
		</script>
	</head>
	<body>
		Click a bottom. You should see two alert saying "Loaded!" and "External function call!".
		<hr>
		<input type="button" onclick="LoadUsingCreateElement()" value="Load script using createElement()">
		<input type="button" onclick="LoadUsingXMLHttpRequest()" value="Load script using XMLHttpRequest">
	</body>
</html>
